<template>
  <div
    v-if="confirmDialog.show"
    class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4"
    @click="cancel"
  >
    <div
      class="bg-white rounded-lg max-w-md w-full p-6"
      @click.stop
    >
      <!-- 标题和图标 -->
      <div class="flex items-center mb-4">
        <div class="flex-shrink-0 mr-4">
          <div
            class="w-10 h-10 rounded-full flex items-center justify-center"
            :class="getIconClass(confirmDialog.type)"
          >
            <svg v-if="confirmDialog.type === 'warning'" class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
              <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
            </svg>
            <svg v-else-if="confirmDialog.type === 'danger'" class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
              <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
            </svg>
            <svg v-else class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
              <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
            </svg>
          </div>
        </div>
        <div>
          <h3 class="text-lg font-medium text-gray-900">{{ confirmDialog.title }}</h3>
        </div>
      </div>

      <!-- 消息内容 -->
      <div class="mb-6">
        <p class="text-gray-600">{{ confirmDialog.message }}</p>
      </div>

      <!-- 按钮组 -->
      <div class="flex space-x-3">
        <button
          @click="cancel"
          class="flex-1 py-2 px-4 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
        >
          {{ confirmDialog.cancelText }}
        </button>
        <button
          @click="confirm"
          class="flex-1 py-2 px-4 rounded-md text-white focus:outline-none focus:ring-2 focus:ring-offset-2"
          :class="getButtonClass(confirmDialog.type)"
        >
          {{ confirmDialog.confirmText }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
const { confirmDialog, confirm, cancel } = useConfirm()

const getIconClass = (type) => {
  const classMap = {
    info: 'bg-blue-100 text-blue-600',
    warning: 'bg-yellow-100 text-yellow-600',
    danger: 'bg-red-100 text-red-600'
  }
  return classMap[type] || classMap.info
}

const getButtonClass = (type) => {
  const classMap = {
    info: 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500',
    warning: 'bg-yellow-600 hover:bg-yellow-700 focus:ring-yellow-500',
    danger: 'bg-red-600 hover:bg-red-700 focus:ring-red-500'
  }
  return classMap[type] || classMap.info
}
</script>